package com.mydemo.function;

import com.mydemo.entity.Driver;

import java.util.Random;

public class Level {

    // 计算司机等级
    public static int calculateLevel(Driver driver) {
        int totalExperience = 0;
        int level = 0;

        while (totalExperience <= driver.getExperience()) {
            totalExperience += level * 100;
            level++;
        }

        // 将等级减1以获得当前等级
        level--;
        return level;
    }

    // 计算距离下一级还差多少经验
    public static int experienceToNextLevel(Driver driver) {
        int experienceNeeded = 0;

        // 计算当前等级升级所需的经验
        for (int i = 0; i < driver.getLevel() + 1; i++) {
            experienceNeeded += i * 100;
        }

        return experienceNeeded - driver.getExperience();
    }

    // 计算薪水的方法
    public static int calculateSalary(Driver driver) {
        int level = driver.getLevel();
        int baseSalary = 100;
        Random random = new Random();
        int randomAdjustment = random.nextInt(21) - 10; // 随机在 -10 到 10 之间调整
        //工资与等级的关系为 工资 = 基本工资 + 等级 * 100 + 随机加减工资;
        return baseSalary + randomAdjustment + driver.getLevel() * 100;
    }
}
